package com.mds.organ.entity;

import com.haulmont.chile.core.annotations.NamePattern;
import com.haulmont.cuba.core.entity.FileDescriptor;
import com.haulmont.cuba.core.entity.StandardEntity;
import com.haulmont.cuba.core.entity.annotation.Lookup;
import com.haulmont.cuba.core.entity.annotation.LookupType;
import com.haulmont.cuba.core.entity.annotation.OnDeleteInverse;
import com.haulmont.cuba.core.global.DeletePolicy;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

@Table(name = "MDSORGAN_ORGAN")
@Entity(name = "mdsorgan_Organ")
@NamePattern("%s|name")
public class Organ extends StandardEntity {
    private static final long serialVersionUID = -2364935988280929651L;

    @Column(name = "NAME", length = 100)
    @NotNull(message = "不能为空")
    private String name;

    @Lookup(type = LookupType.SCREEN, actions = "lookup")
    @OnDeleteInverse(DeletePolicy.CASCADE)
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PARENT_ID")
    private Organ parent;

    @Column(name = "CODE", length = 30)
    private String code;

    @Column(name = "TYPE_")
    private Integer type;

    @Column(name = "ADDRESS")
    private String address;

    @JoinColumn(name = "PHOTO_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    @Lookup(type = LookupType.DROPDOWN, actions = {"lookup", "open"})
    private FileDescriptor photo;

    @Column(name = "PHONE", length = 50)
    private String phone;

    @Column(name = "MOBILE", length = 50)
    private String mobile;

    @Column(name = "FAX", length = 50)
    private String fax;

    @Column(name = "WEBSITE")
    private String website;

    @Column(name = "ZIPCODE", length = 10)
    private String zipcode;

    public void setPhoto(FileDescriptor photo) {
        this.photo = photo;
    }

    public FileDescriptor getPhoto() {
        return photo;
    }

    public Organ getParent() {
        return parent;
    }

    public void setParent(Organ parent) {
        this.parent = parent;
    }

    public String getZipcode() {
        return zipcode;
    }

    public void setZipcode(String zipcode) {
        this.zipcode = zipcode;
    }

    public String getWebsite() {
        return website;
    }

    public void setWebsite(String website) {
        this.website = website;
    }

    public String getFax() {
        return fax;
    }

    public void setFax(String fax) {
        this.fax = fax;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public OrganType getType() {
        return type == null ? null : OrganType.fromId(type);
    }

    public void setType(OrganType type) {
        this.type = type == null ? null : type.getId();
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}